<template>
	<div class="app-container">
		<list-frames :loading="loading">
			<el-form slot="form" :model="queryData" ref="queryForm" size="small" :inline="true" v-if="showSearch">
				<el-form-item label="姓名" prop="userName">
					<el-input v-model="queryData.userName" placeholder="请输入姓名" clearable style="width: 180px" />
				</el-form-item>
				<el-form-item label="年份" prop="year">
					<el-date-picker v-model="queryData.year" type="year" placeholder="选择年份" clearable style="width: 150px"></el-date-picker>
				</el-form-item>
				<el-form-item label="考核等次" prop="result">
					<el-select v-model="queryData.result" placeholder="请选择考核等次" style="width: 150px">
						<el-option v-for="(item, index) in dict.type.sp_examine_level" :key="index" :label="item.label" :value="item.value"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" @click="queryTableData()">搜索</el-button>
					<el-button icon="el-icon-refresh" @click="handleResetQuery()">重置</el-button>
				</el-form-item>
			</el-form>

			<template slot="button">
				<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleOpenDialog()" v-hasPermi="['spm:year:add']">新增</el-button>
				<template v-if="checkedIds.length > 0">
					<el-button type="danger" plain icon="el-icon-delete" size="mini" @click="handleDeleteData()" v-hasPermi="['spm:year:remove']">
						删除
					</el-button>
				</template>
				<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExportData('year')" v-hasPermi="['spm:year:export']">
					导出
				</el-button>
			</template>
			<right-toolbar slot="handle" :showSearch.sync="showSearch" @queryTable="queryTableData()"></right-toolbar>
			<el-table slot="table" height="100%" :data="tableData" @selection-change="handleSelectionChange($event, 'examineId')">
				<el-table-column type="selection" width="55" align="center" />
				<el-table-column label="姓名" prop="userName" min-width="160" />
				<el-table-column label="年份" align="center" prop="year" min-width="160" />
				<el-table-column label="考核等次" align="center" min-width="120">
					<template slot-scope="{ row }">
						<dict-tag :options="dict.type.sp_examine_level" :value="row.result" />
					</template>
				</el-table-column>
				<el-table-column label="是否校先进个人" align="center" min-width="120">
					<template slot-scope="{ row }">
						<dict-tag :options="dict.type.sys_yes_no" :value="row.isAdvanced" />
					</template>
				</el-table-column>
				<el-table-column label="操作" width="116" class-name="small-padding fixed-width">
					<template slot-scope="{ row }">
						<el-button type="text" icon="el-icon-edit" @click="handleOpenDialog(row.examineId)" v-hasPermi="['spm:year:edit']">修改</el-button>
						<el-button type="text" icon="el-icon-delete" @click="handleDeleteData(row.examineId)" v-hasPermi="['spm:year:remove']">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<template slot="page" v-if="dataCount > 0">
				<pagination :total="dataCount" :page.sync="queryData.pageNum" :limit.sync="queryData.pageSize" @pagination="queryTableData()" />
			</template>
		</list-frames>
		<form-dialog v-model="formDialog" :data-id="dataId" @finish="queryTableData()"></form-dialog>
	</div>
</template>

<script>
import formDialog from './form';
import listMixins from '../common/listMixins';
import { listYear, delYear } from '@/api/personnal/examine';

export default {
	name: 'Year',
	mixins: [listMixins],
	components: { formDialog },
	dicts: ['sp_examine_level', 'sys_yes_no'],
	data() {
		return {
			pageName: '年度考核'
		};
	},
	computed: {
		userId() {
			return this.$route.query.id;
		},
		delFunction() {
			return eval(delYear);
		},
		exportUrl() {
			return 'spm/year/export';
		}
	},
	methods: {
		//获取列表数据
		async getTableData() {
			let params = { ...this.queryData };
			let result = await listYear(params);
			this.loading = false;
			if (result.code === 200) {
				this.dataCount = result.total;
				this.tableData = result.rows || [];
			}
		}
	}
};
</script>
